//
//  UserInfoEidtViewController.m
//  YJlandlord
//
//  Created by 文彬 on 2018/6/26.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "UserInfoEidtViewController.h"
#import "MessItemTableViewCell.h"
#import "InputItemTableViewCell.h"
#import "UserDescriptionViewController.h"
#import "ImagePickerTool.h"

@interface UserInfoEidtViewController ()<UITableViewDelegate,
    UITableViewDataSource>

@property (strong, nonatomic) UITableView *listTableView;

@end

@implementation UserInfoEidtViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"个人资料编辑";
    
    [self initPageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark 页面相关
- (void)initPageControl{
    
    [self.view addSubview:self.listTableView];
    [self.listTableView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    
    [StaticTools addTableViewFootButton:self.listTableView
                                  title:@"保存"
                              titleFont:[UIFont systemFontOfSize:18]
                        backgroundColor:[UIColor whiteColor]
                             titleColor:kMainOriginColor
                           buttonHeight:50
                              topMargin:15
                             leftMargin:0
                                  click:^(id param) {
                                      
                                      
                                      
                                  }];
}


#pragma mark UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 7;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  
    return 55;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        
        MessItemTableViewCell *cell = [[NSBundle mainBundle] loadNibNamed:@"MessItemTableViewCell" owner:nil options:nil][0];
        cell.detailLabel.textColor = [UIColor lightGrayColor];
        cell.titleLabel.text = @"头像";
        cell.detailLabel.text = @"上传头像";
        [cell.arrowImgView remakeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@40);
            make.height.equalTo(@40);
            make.right.equalTo(@-10);
            make.centerY.equalTo(cell.centerY);
        }];
        cell.arrowImgView.layer.cornerRadius = 20;
        cell.arrowImgView.clipsToBounds = YES;
        [cell showImage:NO];
        [cell.arrowImgView sd_setImageWithURL:[NSURL URLWithString:@"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4036889747,3526425271&fm=27&gp=0.jpg"] placeholderImage:nil];
        return cell;
        
        
    }
    else if (indexPath.row==1) {
        InputItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InputItemTableViewCell"];
        cell.titleLabl.text = @"昵称";
        cell.inputTxtField.placeholder = @"取个特别的名字";
        
        return cell;
    }
    
    MessItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessItemTableViewCell"];
    [cell showImage:NO];
    cell.detailLabel.textColor = [UIColor lightGrayColor];
    if (indexPath.row==2) {
        cell.titleLabel.text = @"性别";
        cell.detailLabel.text = @"请选择您的性别";
    }
    else if (indexPath.row==3) {
        cell.titleLabel.text = @"年龄";
        cell.detailLabel.text = @"请选择您的年龄";
    }
    else if (indexPath.row==4) {
        cell.titleLabel.text = @"行业";
        cell.detailLabel.text = @"请选择您的行业";
    }
    else if (indexPath.row==5) {
        cell.titleLabel.text = @"故乡";
        cell.detailLabel.text = @"请选择您的故乡";
    }
    else if (indexPath.row==6) {
        cell.titleLabel.text = @"简介";
        cell.detailLabel.text = @"";
    }
    return cell;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
            {
                [[ImagePickerTool sharePicker] showImagePicker:self allowEdit:YES complete:^(id param) {
                    
                }];
            }
            break;
        case 6: //简介
        {
            UserDescriptionViewController *desController = [[UserDescriptionViewController alloc]init];
            [self.navigationController pushViewController:desController animated:YES];
        }
            break;
            
        default:
            break;
    }
    
}

#pragma mark getter
- (UITableView*)listTableView{
    if (_listTableView==nil) {
        _listTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.sectionFooterHeight = 0;
        _listTableView.separatorColor = kLineColor;
        _listTableView.backgroundColor = [UIColor clearColor];
        [_listTableView registerNib:[UINib nibWithNibName:@"MessItemTableViewCell" bundle:nil] forCellReuseIdentifier:@"MessItemTableViewCell"];
        [_listTableView registerNib:[UINib nibWithNibName:@"InputItemTableViewCell" bundle:nil] forCellReuseIdentifier:@"InputItemTableViewCell"];
    }
    
    return _listTableView;
}

@end
